package Manager;

import Entity.Branch;
import java.util.ArrayList;

/**
 *
 * @author CONG
 */
public class BranchManager {
    private ArrayList<Branch> listBranch;

    public BranchManager() {
        listBranch=new ArrayList<Branch>();
    }
    public void getBranchList(ArrayList<Branch> br){
    listBranch.addAll(br);
    }
    public int getSize(){
        return listBranch.size();
    }
    public Branch getBranch(int index){
        return listBranch.get(index);
    }
    public boolean addBranch(Branch br){
        for (int i = 0; i < listBranch.size(); i++) {
            if(listBranch.get(i).getBranchCode()==br.getBranchCode()){
                return false;
            }
        }
        listBranch.add(br);
        return true;
    }
    public boolean updateBranch(Branch br){
        for (int i = 0; i < listBranch.size(); i++) {
            if(listBranch.get(i).getBranchCode()==br.getBranchCode()){
                listBranch.set(i, br);
                return true;
            }
        }
        return false;
    }
    public boolean deleteBranch(Branch br){
        for (int i = 0; i < listBranch.size(); i++) {
            if(listBranch.get(i).getBranchCode()==br.getBranchCode()){
                listBranch.remove(i);
                return true;
            }
        }
        return false;
    }
}
